<%@ page language="java" import="java.util.*,java.sql.*"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="com.bean.LoginBean"%>
<%
	LoginBean LoginBean = (LoginBean) session.getAttribute("Loginbean");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>履历管理</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

</head>
<body>

	<%
		//定义四个分页会用到的变量
		int pageSize = 5;
		int pageNow = 1;//默认显示第一页
		int rowCount = 0;//该值从数据库中查询
		int pageCount = 0;//该值是通过pageSize和rowCount
		String key = request.getParameter("key")==null?"":request.getParameter("key");
		String dept=LoginBean.getDept();
		String s_pageNow = request.getParameter("pageNow");
		if (s_pageNow != null) {
			//接收到了pageNow
			pageNow = Integer.parseInt(s_pageNow);
		}
		//查询得到rowCount
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		String url = "jdbc:mysql://localhost:3306/graduatedesign";
		String user = "root";
		String password = "root";
		Connection conn = DriverManager.getConnection(url, user, password);
		Statement sm = conn.createStatement();
		String sql1="select COUNT(DISTINCT username  )from userrecord where  dept='"+dept+"'";
		if(!key.equals(""))
     	{
     		sql1+=" and username like '%"+key+"%' ";
     	}
		ResultSet rs = sm.executeQuery(sql1);

		if (rs.next()) {
			rowCount = rs.getInt(1);
		}
		//计算pageCount
		if (rowCount % pageSize == 0) {
			pageCount = rowCount / pageSize;
		} else {
			pageCount = rowCount / pageSize + 1;
		}
		//查询出需要显示的记录
		String sql2="select id,username,xiangmu,begindate,enddate,details from userrecord where dept='"+dept+"'";
		if(!key.equals(""))
     	{
     		sql2+=" and username like '%"+key+"%'";
     	}
     	sql2+=" group by begindate limit " + (pageNow-1)*pageSize+","+ pageSize;
		rs=sm.executeQuery(sql2);
	%>
	<form id="form1" name="form1" method="get" action="admin/userrcdmanage.jsp">
	<table width="100%" border="0" cellpadding="0" cellspacing="1"
			bgcolor="#BBD3EB">
			<tr>
				<td height="26" align="center" bgcolor="#FFFFFF">请输入相关信息</td>
				<td height="26" align="left" bgcolor="#FFFFFF">按人员查询： &nbsp;<input
					name="key" type="text" value="<%=key %>" id="textfield" />&nbsp; <input
					type="submit" name="button" id="button" value="查询" /></td>
			</tr>
	</table>
	</form>

	<table width="100%" border="0" cellpadding="0" cellspacing="1"
		bgcolor="#BBD3EB">
		<tr>
			<td height="27" align="center"
				background="/officeoa/admin/images/index1_72.gif" bgcolor="#FFFFFF">员工</td>
			<td height="27" align="center"
				background="/officeoa/admin/images/index1_72.gif" bgcolor="#FFFFFF">项目</td>
			<td height="27" align="center"
				background="/officeoa/admin/images/index1_72.gif" bgcolor="#FFFFFF">开始时间</td>
			<td height="27" align="center"
				background="/officeoa/admin/images/index1_72.gif" bgcolor="#FFFFFF">结束时间</td>
			<td height="27" align="center"
				background="/officeoa/admin/images/index1_72.gif" bgcolor="#FFFFFF">负责的模块</td>
			<td height="27" align="center"
				background="/officeoa/admin/images/index1_72.gif" bgcolor="#FFFFFF">删除</td>
		</tr>
		<%
			while (rs.next()) {
		%>
		<tr>
			<td height="26" align="center" bgcolor="#FFFFFF"><%=rs.getString(2)%></td>
			<td height="26" align="center" bgcolor="#FFFFFF"><%=rs.getString(3)%></td>
			<td height="26" align="center" bgcolor="#FFFFFF"><%=rs.getString(4)%></td>
			<td height="26" align="center" bgcolor="#FFFFFF"><%=rs.getString(5)%></td>
			<td height="26" align="center" bgcolor="#FFFFFF"><%=rs.getString(6)%></td>
			<td height="26" align="center" bgcolor="#FFFFFF"><a href="userrcddid?id=<%=rs.getInt(1)%>" onclick="alert('删除成功')">删除</a>
			</td>
		</tr>
		<%
			}
		%>

	</table>
	<table width="100%" border="0" cellpadding="0" cellspacing="1"
		bgcolor="#BBD3EB">

		<%
			//上一页
			if (pageNow != 1) {
				out.println("<a href=admin/userrcdmanage.jsp?pageNow="
						+ (pageNow - 1) + ">上一页</a>");
			}
			//显示超链接
			for (int i = 1; i <= pageCount; i++) {
				out.println("<a href=admin/userrcdmanage.jsp?pageNow=" + i + ">["
						+ i + "]</a>");
			}
			//下一页
			if (pageNow != pageCount) {
				out.println("<a href=admin/userrcdmanage.jsp?pageNow="
						+ (pageNow + 1) + ">下一页</a>");
			}
		%>
		</table>

</body>
</html>
